某Map中散乱的存放着如下信息:
abce.com (1), cde.com (1), abc.com (3), def.com (1), abd.com (2), sfaf.com (1), bcd.com (2)
为了进行排寻 使用ArrayList的sort进行排序.
通过new ArrayList(collection) 将Map中的Value引用到新建立的ArrayList中,
//--以下为排序 ArrayListalDomains = new ArrayList (); alDomains = new ArrayList (domains.values()); System.out.println(alDomains); Collections.sort(alDomains, null); System.out.println(alDomains);
打印:
[abce.com (1), cde.com (1), abc.com (3), def.com (1), abd.com (2), sfaf.com (1), bcd.com (2)] – 排序前
[abc.com (3), abce.com (1), abd.com (2), bcd.com (2), cde.com (1), def.com (1), sfaf.com (1)] – 排序后
HashSet – 覆盖equals, hashCode <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.